def merge_file(source,target):
    with open(source, 'r', encoding='utf-8') as read_file:
        lines = read_file.readlines()
        for line in lines:
            line = line.rstrip()
            with open(target, 'a', encoding='utf-8') as write_file:
                write_file.write(line+'\n')

def write_dict_to_file(output_file,dict_gram):
     with open(output_file, 'w', encoding='utf-8') as write_file:
        for (key,value) in dict_gram.items():
            line = str(key) +","+str(value)
            line = line.rstrip()
            write_file.write(line+'\n')

def write_list_to_file(output_file,line_list):
    with open(output_file,'w',encoding='utf-8') as write_file:
        for line in line_list:
            #line = line.rstrip
            write_file.write(line+'\n')

def read_list_from_file(input_file):
    line_list = []
    with open(input_file,'r',encoding='utf-8') as read_file:
        lines = read_file.readlines()
        for line in lines:
            line_list.append(line)
    return line_list

def read_dict_from_file(input_file):
    gram_dict = {}
    with open(input_file,'r',encoding='utf-8') as read_file:
        lines = read_file.readlines()
        for line in lines:
            parts = line.split(',')
            gram_dict[parts[0]] = parts[1]
    return gram_dict

